<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title></title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../static/lib/layui/css/layui.css" media="all" />
  <link rel="stylesheet" href="../../static/css/admin.css" media="all" />
</head>

<body>
  <div class="layui-form" lay-filter="tmm-app-form-list" id="tmm-order-duplicate-form" style="padding: 20px 30px 0 0;">
    <input type="hidden" value="${voucher}" id="voucher">
    <div class="layui-form-item">
      <div class="layui-input-block">
        <input type="radio" name="type" value="1" lay-verify="required"  title="未重单"  lay-filter="type" <c:if test="${voucher.type==1}">checked</c:if>>
        <input type="radio" name="type" value="2" lay-verify="required"  title="重单" lay-filter="type" <c:if test="${voucher.type==2}">checked</c:if> >
      </div>
    </div>
    <div class="layui-form-item" id="uploadDiv">
<%--      <c:choose>--%>
<%--        <c:when test="${voucher.file_name!=null}">--%>
<%--          ${voucher.file_name}<a href="javascript:void (0)" onclick="del()">删除</a><a href="javascript:void (0)" id="upload">重新上传</a>--%>
<%--        </c:when>--%>
<%--        <c:otherwise>--%>
<%--          <a href="javascript:void (0)" id="upload">上传凭证</a>--%>
<%--        </c:otherwise>--%>
<%--      </c:choose>--%>
    </div>
  </div>

  <script src="../../static/lib/layui/layui.js"></script>
  <script>
    layui.config({
      base: "../../static/js/"
    }).extend({
      index: 'index'
    }).use(['index', 'form','upload'], function () {
      var $ = layui.$
        , form = layui.form
        , upload = layui.upload;

        if(${voucher.order_sn!=null}){
            parent.document.getElementById('duplicateImg').value="${voucher.pic}";
            parent.document.getElementById('file_name').value="${voucher.file_name}";
            parent.document.getElementById('type').value="${voucher.type}";
        }

        form.on('radio(type)', function (data) {
            $("#uploadDiv").empty()
            if(data.value==2){
              $("#uploadDiv").append('<a href="javascript:void (0)" id="upload">上传凭证</a>')
              upload.render({
                elem: "#upload",
                url: "${path}/upload/uploadFile",
                data:{uploadUrl:"temp/"},
                size:2048,
                multiple: true,
                before: function (obj) {
                  //预读本地文件示例，不支持ie8
                  obj.preview(function (index, file, result) {
                    parent.document.getElementById('file_name').value=file.name;
                    $("#uploadDiv").empty().append(file.name+'<a href="javascript:void (0)" onclick="del()">删除</a><a href="javascript:void (0)" id="upload">重新上传</a>')
                  });
                },
                done: function (res) {
                  // 上传完成
                  if(res.code<0){
                    layer.alert("上传文件失败",{icon:2});
                    return;
                  }
                  parent.document.getElementById('duplicateImg').value=res.data;
                  parent.document.getElementById('type').value=$("input[name='type']:checked").val();

                }
              });
            }
            parent.document.getElementById('type').value=data.value;
        });
    })
    function del() {
        parent.document.getElementById('duplicateImg').value="";
        parent.document.getElementById('file_name').value="";
        parent.document.getElementById('type').value=0;
        location.reload();
    }
  </script>
</body>

</html>